package de.tabreaderandroid.tabreader.preferences;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * @author André Stannek
 *
 */
public class SQLHelper extends SQLiteOpenHelper {

	public static final String TABLE_FOLDERS = "folders";
	public static final String COLUMN_FOLDER = "folder";

	private static final String DATABASE_NAME = "tabreader.db";
	private static final int DATABASE_VERSION = 1;

	private static final String DATABASE_CREATE = "create table "
			+ TABLE_FOLDERS + "(" + COLUMN_FOLDER + " text primary key);";

	/**
	 * @param context
	 *            the {@link Context} this helper is used in
	 */
	public SQLHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(SQLHelper.class.getName(), "Upgrading database from version "
				+ oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_FOLDERS);
		onCreate(db);
	}

}
